<template>
	<view class="recommend">
        <block v-if="localSuccess">
            <view class="scroll-height">
            <!-- #ifdef MP-WEIXIN -->
            <view class="recommend-head">
                <top-nav :inner-title="title" is-show-back="false" is-fixed="true" :navH="navH" :n="n" is-white="bg-white" opacity="1"></top-nav>
                <block v-if="showAddBar">
                    <view  class="add_mine_bar_out" :style="{top:navH + 'px'}">
                        <view class="add_mine_bar">
                            <view>添加到我的小程序，下单更快捷</view>
                            <button @click="showAdd()">添加</button>
                        </view>
                    </view> 
                </block>  
            </view>
             <view class="recommend-space" :style="{height:showAddBar ? navH +35 +'px' : navH + 'px'}"></view>
            <!-- #endif -->
            <view class="address_head">
                <view class="recommend-pos" @click="selectCity()">
                    <icon class="recommend-local"></icon>
                    <text class="ellipsis">{{ localSchool }}</text>
                    <icon class="recommend-i"></icon>
                </view>
                <!-- #ifdef MP-WEIXIN -->
                <button open-type='share' class="share">
                    <image src="http://img1.birdback.org/a/10/99/109934b1f9b83a88e1551f9770920bf2.png"></image>
                </button>
                <!-- #endif -->
                
            </view>
            <block v-if="searchFixed">
                <view  class='search-fixed' id="search" :style='{top: searchTop + "px"}'>
                    <view class="search">
                        <view class="search_inner">
                           <view class="search-item" @click="toSearch(searchKey)">
                                <image src="http://juhuijia2.birdback.org/mapi/i/run/search@3x.png"></image>
                                <text>{{searchKey}}</text>
                            </view>   
                        </view>
                       <!-- <view class="search-list">
                            <view>热搜:</view>
                            <view class="search-list-item ellipsis" @click="toSearch(item)" v-for="(item, index) in searchKeyList" :key="index">{{item}}</view>
                        </view> -->
                    </view>
                </view>
            </block>
            <block v-else>
                <view  class='' id="search" :style='{top: searchTop + "px"}'>
                    <view class="search">
                        <view class="search_inner">
                           <view class="search-item" @click="toSearch(searchKey)">
                                <image src="http://juhuijia2.birdback.org/mapi/i/run/search@3x.png"></image>
                                <text>{{searchKey}}</text>
                            </view>   
                        </view>
                       <!-- <view class="search-list">
                            <view>热搜:</view>
                            <view class="search-list-item ellipsis" @click="toSearch(item)" v-for="(item, index) in searchKeyList" :key="index">{{item}}</view>
                        </view> -->
                    </view>
                </view>
            </block>
           
            <view :style="{height: searchFixed ? '30px' : '0'}"></view>
            <!-- banner -->
            <view class="ad" v-if="imgUrls.length>0">
                <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration" :circular="circular"
                 :indicator-color="indicatorColor" :indicator-active-color="indicatorActiveColor" :current="current">
                    <swiper-item v-for="(item, index) in imgUrls" :key="index">
                        <image :data-index="index" :src="item.icon" class="slide-image" @click="adEvent($event)" lazy-load="true"></image>
                    </swiper-item>
                </swiper>
            </view>
            <!-- 品类滑动 -->
            <swiper class="categoryList" indicator-active-color="rgba(141,239,208,1)">
                <block v-for="(item, index) in categoryList" :key="index">
                    <swiper-item>
                        <block v-for="(item, index) in item" :key="index">
                            <view class="category-info" :data-index="index" :data-id="item.id" @click="menuEvent($event)">
                                <image :src="item.icon" class="category-image" lazy-load="true"></image>
                                <view class="category-text">{{item.title}}</view>
                            </view>
                        </block>
                    </swiper-item>
                </block>
            </swiper>
            <!-- 超值抢购 -->
            <view class="group-active" v-if="goodsList.length > 0">
                <view class="group-title oneself-title">
                    <view>
                        <text>超值抢购</text>
                        <!-- <view class="active-time">
                            <text>{{activeTime[0]}}</text>:<text>{{activeTime[1]}}</text>:<text>{{activeTime[2]}}</text>
                        </view> -->
                        <text class="discount_icon">狠优惠</text>
                    </view>
                    <view class="sum-text" @click="activeEvent()" v-if="goodsList.length>2">
                        <view>更多</view>
                        <icon class='arr_right'></icon>
                    </view>
                </view>
                <scroll-view class="group-img flex" scroll-x>
                    <block v-for="(item, index) in goodsList" :key="index">
                        <view class="goods-index-1 column" :mode="groupMode"  @click='openStore($event)' :data-storeid='item.store_id' :data-categoryId='item.category_id' :data-id='item.id'>
                            <image :src="item.img_path" lazy-load="true"></image>
                            <view class="active_title ellipsis">店铺热销</view>
                            <view class="goods_info flex column">
                                <view class="goods_name ellipsis">{{item.name}}</view>
                                <view class="shop-tags flex">
                                    <view class="goods_price">¥<text>{{item.price}}</text></view>
                                    <view class="sales_content flex" v-if="item.discount>0 || item.num_discount>0">
                                        <block v-if="item.discount > 0">{{item.discount}}折 </block> 
                                        <block v-if="item.discount>0 && item.num_discount>0">
                                            <text></text>
                                        </block>
                                        <block v-if="item.num_discount> 0">限{{item.num_discount}}份</block>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </block>
                </scroll-view>
            </view>
            <!-- 品牌推荐 -->
            <block v-if="recommendInfo.goods_list.length > 0">
                <view class="recommend-shop">
                    <view class="recommend-shop-head">
                        <view class="recommend-shop-img">
                            <image :src="recommendInfo.icon_url" mode="aspectFit"  lazy-load="true"></image>
                        </view>
                        <view class="recommend-shop-info">
                            <text class="recommend-shop-title">{{recommendInfo.shop_name}}</text>
                            <text class="recommend-tag" v-if="recommendInfo.active_list.length>0">
                                <block v-for="(item, index) in recommendInfo.active_list" :key="index" v-if="index<5">
                                    <text>{{item.text}}</text>
                                </block>
                            </text>
                        </view>
                        <view class="recommend-shop-icon">
                            <image src="http://img1.birdback.org/a/b7/a5/b7a5ee707e16ccdab8af02990e24a430.png"></image>
                        </view>
                    </view>
                    <scroll-view class="group-img flex" scroll-x>
                        <block v-for="(item, index) in recommendInfo.goods_list" :key="index">
                            <view class="goods-index-1 column" :mode="groupMode"  @click='openStore($event)' :data-storeid='recommendInfo.store_id' :data-categoryId='item.category_id' :data-id='item.id'>
                                <image :src="item.icon"  lazy-load="true"></image>
                                <view class="active_title ellipsis">店铺热销</view>
                                <view class="goods_info flex column">
                                    <view class="goods_name ellipsis">{{item.allName}}</view>
                                    <view class="shop-tags flex">
                                        <view class="goods_price">¥<text>{{item.price}}</text></view>
                                        <view class="sales_content flex" v-if="item.discount.discount > 0 || item.discount.num_discount > 0">
                                            <block v-if="item.discount.discount > 0">{{item.discount.discount}}折 </block>
                                            <block v-if="item.discount.discount > 0 && item.discount.num_discount > 0">
                                                <text></text>
                                            </block>
                                            <block v-if="item.discount.num_discount > 0">限{{item.discount.num_discount}}份</block>
                                             
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </block>
                    </scroll-view>
                </view>
            </block>

            <!--自取-->
            <block v-if="oneselfList.length > 0">
                <view class="oneself">
                    <view class="oneself-title" @click="goOneself()">
                        <view>
                            <text>自取免配送费</text>
                            <image class="oneself-image" src="http://img1.birdback.org/a/e0/49/e049351f17980ae12ed7d65a449b3372.png"></image>
                        </view>
                        <view class="oneself_content">
                            <view class="sum-text">
                                <view>共{{oneselfCount}}家</view>
                                <icon class='arr_right'></icon>
                            </view>
                        </view>
                    </view>
                    <view class='scroll_out'>
                        <scroll-view class="oneself-view" scroll-x @scroll="srollToLeft">
                            <block v-for="(item,index) in oneselfList" :key="index">
                                <view :data-storeid='item.id' @click='goOneselfStore($event)'>
                                    <image :src="item.shop_img"></image>
                                    <text class="oneself-view-title">{{item.shop_short_name}}</text>
                                    <block v-if="item.send_price > 0">
                                        <text class="oneself-view-price">省￥{{item.send_price}}配送费</text>
                                    </block>
                                    <block v-if="item.send_price <= 0 && item.open_oneself == 2">
                                        <text class="oneself-view-price">仅到店自取</text>
                                    </block>
                                    <block v-if="item.send_price <= 0 && item.open_oneself != 2">
                                        <text class="oneself-view-price">支持自取</text>
                                    </block>
                                </view>
                            </block>
                        </scroll-view>
                        <image @click="goOneself()" class="oneself_more_icon" :class="notShow ? 'not_show' : ''" src="http://img1.birdback.org/a/e3/f3/e3f3609341c7805cedd64f1f6e7a1e07.png"></image>
                    </view>
                </view>
            </block>
            <!-- 开车专区 -->
            <view class="group-active car-active" v-if="groupData.length > 0">
                <view class="group-title oneself-title">
                    <view><text>开车专区</text></view>
                    <view class="sum-text" @click="groupEvent()" v-if="groupData.length>2">
                        <view>更多</view>
                        <icon class='arr_right'></icon>
                    </view>
                </view>
                <scroll-view class="group-img" scroll-x>
                    <block v-for="(item, index) in groupData" :key="index">
                        <view class="group-index-1" :mode="groupMode" @click="openGroupStore($event)" :data-id="item.store_id" :data-time="item.finish_time">
                            <image :src="item.index_shop_icon"></image>
                            <view class="image_shadow">
                                <view class="group-intro group-time" v-if="item.finish_time != ''">
                                    <text class="group-bg">{{item.finish_time}} 送达</text>
                                </view>
                                <view class="group-intro group-name" v-if="item.index_shop_name != ''">
                                    <text class='group-bg'>{{item.index_shop_name}}</text>

                                </view>
                                <view class="group-intro group-text">
                                    <text class=''>{{item.person_num}}人已上车></text>
                                </view>
                            </view>
                        </view>
                    </block>
                </scroll-view>
            </view>
            </view>
            <!-- 排序 -->
            <view class="menu_tab_under"></view>
            <view class="menu_tab" :class="menuFixed ? 'menu-fixed':''" :style='{top:menuTop +"px"}'>
                <view class="condition flex">
                    <view class="menu flex column" :class="sort == 1 || sort == 2 ? 'ac':''" v-if="countList.take_out == 1">
                        <view @click="sortEvent(0)" style="text-align: center;">
                            <view class="title flex">外卖 <icon class="arr_down" v-if="menuFixed"></icon></view>  
                            
                            <view class="sub_title sub_title_select flex" v-if="!menuFixed">
                                <text v-if="pickerSelect==1">综合排序</text>
                                <text v-if="pickerSelect==2">销量最高</text>
                                <block v-if="sort>2">
                                    <icon class="arr_down"></icon>
                                </block>
                                <block v-else>
                                    <icon class="arr_down_white" v-if="!selectSort"></icon>
                                    <icon class="arr_up_white" v-else></icon>
                                </block>
                            </view>
                        </view>
                        <view class="picker_select" v-if="selectSort && countList.take_out == 1">
                            <view class="picker_select_column">
                                <view @click="sortEvent(1)" :class="sort==1 ? 'pickered' : ''"><text>综合排序</text>
                                    <icon :class="sort==1 ? 'picker_chosed' : ''"></icon>
                                </view>
                                <view @click="sortEvent(2)" :class="sort==2 ? 'pickered' : ''"><text>销量最高</text>
                                    <icon :class="sort==2 ? 'picker_chosed' : ''"></icon>
                                </view>
                            </view>
                        </view>
                    </view>
                    <view class="menu flex column" :class="sort == 3?'ac':''" @click="sortEvent(3)" v-if="countList.oneself == 1">
                        <view class="title flex">自取</view>
                        <view class="sub_title flex" v-if="!menuFixed">免配送费</view>
                    </view>
                    <view class="menu flex column" :class="sort == 4?'ac':''" @click="sortEvent(4)" v-if="countList.car == 1">
                        <view class="title flex">开车</view>
                        <view class="sub_title flex" v-if="!menuFixed">拼团优惠</view>
                    </view>
                    <view class="menu flex column" :class="sort == 5?'ac':''" @click="sortEvent(5)" v-if="countList.run == 1">
                        <view class="title flex">跑腿</view>
                        <view class="sub_title flex" v-if="!menuFixed">代拿代取</view>
                    </view>
                </view>
            </view>
            <view  :style="{height: menuFixed ? '44px' : '0'}"></view>
            <block v-if="!isEmpty">
            <view class="shop_list_content" :style="{minHeight: loadBeforeHeight + 'px'}">
       
                <view class="shop_list_content_2">
                        <block v-if="sort == 4" v-for="(item,index) in shopInfoList" :key="index">
                            <view class="shop-list-item" @click="openGroupStore($event)" :data-id="item.store_id" :data-time="item.finish_time">
                                <view class="shop-info-left">
                                    <image class="shop-info-img" :src="item.icon_url" lazy-load="true"></image>
                                </view>
                                <view class="shop-info-detail">
                                    <view class="shop-info-detail-name ellipsis" v-if="item.shop_name">{{item.shop_name}}</view>
                                    <view class="shop-info-detail-middle">
                                        <text class="shop-info-detail-sales" v-if="item.finish_time">当前班次：{{item.finish_time}}</text>
                                    </view>
                                    <view class="shop-info-detail-middle">
                                         <block v-if="item.wait_class.length>0">
                                            <view v-for="(item,index) in item.wait_class" :key="index" class="shop-info-detail-sales" :class=" idx == 0?'t1':''" v-if="item">剩余班次：{{item}}</view>
                                        </block>
                                    </view>
                                    <!-- <button @click="activeEvent(item.store_id)" class="btn">立即上车</button> -->
                                </view>
                            </view>
                        </block>
                        <block v-if="sort != 4"v-for="(item, index) in shopInfoList" :data-storeid='item.id' :key="index">
                            <view  class="shop-list-item">
                                <view class="shop-info-left" @click='openStore($event)' :data-storeid='item.id'>
                                    <block v-if='item.disable && item.reserve_status != 1'>
                                        <view class='close'></view>
                                    </block>
                                    <block  v-if="item.type == 1">
                                        <view class='big_brand'></view>
                                    </block>
                                    <block v-if="item.new_store ==  1">
                                        <view class='new_store'></view>
                                    </block>
                                    
                                    <image class="shop-info-img" :src="item.shop_img" mode="widthFix"></image>
                                </view>
                                <view class="shop-info-detail">
                                    <view class="shop-info-top" @click='openStore($event)' :data-storeid='item.id'>
                                        <view class="shop-info-detail-name ellipsis" v-if="item.shop_name">
                                            {{item.shop_name}}
                                        </view>
                                        <view class="shop-info-detail-middle" v-if=" item.reserve_status == 1 && item.disable != 0 ">
                                            <view class="reser_icon">接受预定中</view>
                                        </view>
                                        <view class="shop-info-detail-middle">
                                            <view class="shop-info-detail-sales flex">
                                                <view class="flex store_score">
                                                    <block v-if="item.star>0">
                                                        <icon class="star_icon star_yellow"></icon>
                                                        <text class="yellow_text">{{item.star}}</text>
                                                    </block>
                                                    <block v-else>
                                                        <icon class="star_icon star_gray"></icon>
                                                        <text class="light_text">暂无评分</text>
                                                    </block>
                                                </view>
                                                <text  v-if="item.month_order">月售{{item.month_order}}</text>
                                            </view>
                                            <view class="shop-info-detail-sales">
                                                <image class="distribution_icon_1" v-if="item.distribution_type == 1" src="http://img1.birdback.org/a/88/91/88917015ffca21c78a2c6aca842a120e.png"></image>
                                                <block v-if='item.icon_tag_url != ""'>
                                                    <image class="icon-tag" :src="item.icon_tag_url"></image>
                                                </block>
                                            </view>
                                        </view>
                                        <view class="shop-info-detail-middle">
                                            <view class="shop-info-detail-other">
                                                <text v-if="item.start_send_price">起送 ￥{{item.start_send_price}}</text>
                                                <view class="slide_text" v-if="item.start_send_price && item.send_price">|</view>
                                                <text v-if="item.send_price">配送 ￥{{item.send_price}}</text>
                                            </view>
                                        </view>
                                    </view>
                                    
                                    <block v-if=' (item.open_oneself != "0" && item.arrAll.length>3) || (item.open_oneself == "0" && item.arrAll.length>5)'>
                                        <view v-if=' item.active_list.length>0 || item.open_oneself != "0" ' class="shop-tags" :class="item.arrowOpen ? 'arrowDown':'arrowUp'" @click='openDiscount($event)' :data-storeid="item.id">
                                            <view class="text_list">
                                                <block v-for='(val,index) in item.arrAll' :key="val">
                                                    <view class="sales_content" :class='((index > 2 && item.open_oneself != "0") || (index > 4 && item.open_oneself == "0")) && item.arrowOpen ? "hide" : ""'>{{val}}</view>
                                                </block>
                                                <view class="sales_content green" v-if="item.open_oneself == '1' ">支持自取</view>
                                                <view class="sales_content green" v-if="item.open_oneself == '2' ">仅支持自取</view>
                                            </view>
                                            <view class="arrow" v-if=' (item.open_oneself != "0" && item.arrAll.length>3) || (item.open_oneself == "0" && item.arrAll.length>5)'></view>
                                        </view>
                                    </block>
                                    <block v-else>
                                        <view v-if=' item.active_list.length>0 || item.open_oneself != "0" ' class="shop-tags" :class="item.arrowOpen ? 'arrowDown':'arrowUp'">
                                            <view class="text_list">
                                                <block v-for='(val,index) in item.arrAll' :key="val">
                                                    <view class="sales_content" :class='((index > 2 && item.open_oneself != "0") || (index > 4 && item.open_oneself == "0")) && item.arrowOpen ? "hide" : ""'>{{val}}</view>
                                                </block>
                                                <view class="sales_content green" v-if="item.open_oneself == '1' ">支持自取</view>
                                                <view class="sales_content green" v-if="item.open_oneself == '2' ">仅支持自取</view>
                                            </view>
                                        </view>
                                    </block>   
                                </view>
                            </view>
                        </block>

                </view>
                <view class="load_before"  :style="{opacity: loadOver ? 1 : 0, height: loadBeforeHeight + 'px'}">      </view>
                
            </view>
            <view class="no-more" v-if="noMore">更多商家接入中，敬请期待！</view>
            </block>
            <block v-else>
                <view class='empty' :style="{minHeight: loadBeforeHeight + 'px'}" @click="">
                    <view class='img'></view>
                    <text>更多商家接入中，敬请期待</text>
                </view>
            </block>
            <!-- 城市切换 -->
            <cascade-box 
                  class="cascade_box" 
                  :animationData="animationData" 
                  :prov="prov" 
                  :city="city" 
                  :school="school"
                  :value = "cascadeVal" 
                  :column1="1"
                  :column2="1"
                  :column3="2.5"
                  @cascadeCancel="cancelEvent()"
                  @cascadeEnter="enterEvent()" 
                  @cascadeChange="bindChange()"
              >
            </cascade-box>
            
            <view class='group-detail-box add_to_mine' v-if="addMine">
                <view class="group-mask" @touchmove.stop.prevent="moveHandle"></view>
                <view class="group-detail-medium" :style="{marginTop: navH + 'px'}">
                    <image class="arr_long" src="http://img1.birdback.org/a/c3/88/c3882222cdc7643aa3b225cd92009a77.png"></image>
                    <view class='title'>1.点击"添加到我的小程序"</view>
                    <view class="content">
                        <image src="http://img1.birdback.org/a/3d/4c/3d4cfd44990fc58ec7ccc524039a0bea.png"></image>
                    </view>
                    <view class='title'>2.下拉微信首页快速进入同学快跑</view>
                </view>
                <button @click="addToMine()">知道了</button>
            </view>
            
            <!-- 天降红包 -->
            <view class='group-detail-box special-packet-box' v-if="packetShow"  style="width: 100%; height: 100%;left: 0; top: 0">
                <view class="group-mask" @touchmove.stop.prevent="moveHandle"></view>
                <view class="group-detail-medium" :style="{marginTop: navH+30 + 'px'}">
                    <view class='packet_list'>  
                       <image class="packet_bg_top" src="http://img1.birdback.org/29011098596.png"></image>
                       <view class="packet_content">
                            <image class="packet_bg_bottom" src="http://img1.birdback.org/20190810885851.png"></image>
                            <view class="store_list">
                                <scroll-view class="store_list" scroll-y="true">
                                    <block  v-for="(item,index) in packetList" :key = "index">
                                        <view class="store_card flex_bar" :class="item.p_img ? '' : 'new_user'">
                                            <image v-if="item.p_img" class="store_img" :src="item.p_img"></image>
                                            <view class="packet_info flex_bar">
                                                <view class="packet_left">
                                                    <view class="store_name">{{item.p_name}}</view>
                                                    <view class="store_tip">{{item.content}}</view>
                                                </view>
                                                <view class="packet_right">
                                                    <view class="packet_value">¥<text>{{item.reduction}}</text></view>
                                                    <view class="red_icon" v-if="item.store_id" @click='openStore($event)' :data-storeid='item.store_id'>去使用</view>
                                                    <view class="red_icon" v-else @click='hidePacketBox()'>去使用</view>
                                                </view>
                                            </view>
                                        </view>
                                    </block>
                                </scroll-view>               
                            </view>
                        </view>
                        <image class="bottom_shadow" src="http://img1.birdback.org/20190809858857828.png"></image>
                    </view>
                    <view class='close_together' @click="hidePacketBox()"> </view>
                </view>
            </view>
            
            <!-- 新用户红包 -->
            <view class='group-detail-box special-packet-box new_packet_box' v-if="newPacketShow"
            style="width: 100%; height: 100%;left: 0; top: 0">
                <view class="group-mask"  @touchmove.stop.prevent="moveHandle"></view>
                <view class="group-detail-medium">
                    <view class='packet_list'>  
                        <image class="packet_bg" src="http://img1.birdback.org/%E6%96%B0%E4%BA%BA%E4%B8%93%E4%BA%AB%E7%BA%A2%E5%8C%85.png"></image>
                        <!-- #ifdef MP-WEIXIN -->
                            <button class="login_bt" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
                                <image src="http://img1.birdback.org/a/16/02/1602a1ea264f8ca31cee89c457d6d838.png"></image>
                            </button>  
                        <!-- #endif -->
                        <!-- #ifdef MP-ALIPAY -->
                            <button class="login_bt" open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>
                                <image src="http://img1.birdback.org/a/16/02/1602a1ea264f8ca31cee89c457d6d838.png"></image>
                            </button>  
                        <!-- #endif -->
                        
                    </view>
                    <view class='close_together' @click="hideNewPacketBox()"> </view>
                </view>
            </view>
            
            <view class="new_packet_bar flex" v-if="showPacketBar">
                <view class="close" @click="closePacketBar()"  @touchmove.stop.prevent="moveHandle"></view>
                <view class="white_text flex">立即登录即可领取新人大礼包</view> 
                <!-- #ifdef MP-WEIXIN -->
                    <button class="green_bt flex" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
                        立即领取
                    </button>  
                <!-- #endif -->
                <!-- #ifdef MP-ALIPAY -->
                    <button class="green_bt flex" open-type="getAuthorize" @getAuthorize="onGetAuthorize" @error="onAuthError" scope='phoneNumber'>
                         立即领取
                    </button>  
                <!-- #endif -->
            </view>
            
            <view class='group-detail-box special-packet-box new_red_box' v-if="newRedShow"  style="width: 100%; height: 100%;left: 0; top: 0">
                <view class="group-mask"  @touchmove.stop.prevent="moveHandle"></view>
                <view class="group-detail-medium" :style="{marginTop: navH + 'px'}">
                    <view class="packet">
                        <image class="packet-bg" src="http://img1.birdback.org/Combined%20Shape%20Copy@3x.png"></image>
                        <view class="packet_top"> 
                            <view class="packet_left">
                                <view class="packet_name">{{newPacket.p_name}}</view>
                                <view class="packet_deadline">满{{newPacket.full}}元可用</view>
                            </view>
                            <view class="packet_right">
                                <view class="packet_value">¥ <text>{{ newPacket.reduction}}</text></view>
                            </view>   
                        </view>
                        <view class="packet_bottom">
                            <view class="packet_tip"> 
                                <view class="tip light_text">{{newPacket.content}}</view>
                            </view>
                        </view>
                    </view>
                    <view class='red_bt' @click="hideNewRed()"></view>
                </view>
            </view>
            
            <view class='group-detail-box login_tip' v-if="showLoginoutTip">
                <view class="group-mask"  @touchmove.stop.prevent="moveHandle"></view>
                <view class="group-detail-medium white_bg flex column">
                    <view class='title'>提示</view>
                    <view class="content">取消后所有的红包均不能使用哟～</view>
                    <view class="bottom flex">
                        <button class="black_bg" hover-class="none" @click="closeBox()">有钱任性</button>
                        <button class="green_bg" hover-class="none" @click="getPacket()">我要优惠!</button>
                    </view>
                </view>
            </view>
        
        </block>
        <block v-else>
            <view class="wrong_page" v-if="!showGroupRule">
                <block v-if=" !noAddress && noNetwork ">
                    <image class="img1" src="../../static/Group23x.png"></image>
                    <view class="text">您的网络好像不太给力，请重新加载</view>
                    <button @click="beforeInitData()">重新加载</button>
                </block>
                <block v-else-if=" !noAddress && !noNetwork ">
                    <text class="text">{{loadText}}</text>    
                </block>
                <block v-else-if=" noAddress && !noNetwork ">
                    <image class="img2" src="../../static/Group3x.png"></image>
                    <view class="text">{{loadText}}，请重新加载</view>
                    <button @click="beforeInitData()">重新加载</button>
                </block>  
                <block v-else>
                    <image class="img2" src="../../static/Group@3x.png"></image>
                    <view class="text">{{loadText}}，请重新加载</view>
                    <button @click="beforeInitData()">重新加载</button>
                </block> 
            </view>
        </block>
	</view>
</template>

<script>
	import uniFly from 'unifly';
	import request from '../../common/request.js';
	import Big from '../../common/big.js';
	import $api_base from '../../api/api_base.js';
	import cascadeBox from '@/template/cascade/index.vue';
	import topNav from '@/template/topnav/index.vue';
	export default {
		components: {
			cascadeBox,
			topNav
		},
		data() {
			return {
                windowHeight:0,
                loadBeforeHeight: 0,
                loadOver: true,
                hideOver: true,
				searchKey: '',
				activeTime: ['00', '00', '00'],
				activeTimer: null,
				groupMode: 'scaleToFill',
				groupData: [],
				imgUrls: [],
				indicatorDots: true,
				autoplay: true,
				circular: true,
				indicatorColor: 'rgba(255,255,255,.5)',
				indicatorActiveColor: '#fff',
				interval: 3000,
				duration: 1000,
				current: 0,
				categoryList: [],
				shopInfoList: [],
                storeList: [],
                goodsList: [],
				oneselfList: [],
                groupList: [],
				oneselfCount: 0,
				recommendInfo: null,
				isEmpty: false,
				localSchool: '定位中.....',
				prov: [],
				city: [],
				school: [],
				school_list: [],
				prov_index: 0,
				city_index: 0,
				school_index: 0,
				selectRegion: {},
				selectSchoolId: 0,
				schoolId: 0,
				animationData: {},
				lock: false,
				lockTime: 0,
				localSuccess: false,
				loadText: '数据加载中...',
				pn: 1,
				pc: 30,
				sort: 1,
				conditionClass: '',
				conditionHeight: '',
				showWxappLogin: false,
				navH: 0,
				n: 0,
				title: '同学快跑',
				noAddress: false,
				noNetwork: false,
				showGetUser: false,
				notShow: true,
				noMore: false,
				selectSort: false,
				pickerSelect: 1,
				menuFixed: false,
				menuTop: 0,
                searchFixed: false,
                searchTop: 0,
                showAddBar: false,
                addMine: false,
                packetShow: false,
                packetList:[],
                newPacketShow: false,
                showLoginoutTip: false,
                showPacketBar: false,
                newRedShow: false,
                isRegisted: false,
                newPacket:{},
                cascadeVal:[0,0,0],
                firstShow:0,
                countList:{},
                backFrom:'',
                scrollTop: 0
			};
		},

		onLoad(options) {
            console.log(options);
			var schoolId = 0;
			if (options.q && options.q != 'undedined') {
				//扫码进首页
				var q = decodeURIComponent(options.q);
				var qq = q.indexOf('?');
				if (qq > 0) {
					// 存在参数
					var qOptions = q.substring(qq + 1, q.length); //获取所有的参数
					var qList = qOptions.split('&');
					var string = {};
					for (let i in qList) {
						let qList_v = qList[i].split('=');
						string[qList_v[0]] = qList_v[1];
					}
					schoolId = string.schoolId || getApp().globalData.schoolId;
				} else {
					schoolId = getApp().globalData.schoolId || 0;
				}
			} else {
				schoolId = options.schoolId || getApp().globalData.schoolId;
			}
            var isMine = uni.getStorageSync('ISMINE');
            if(isMine == 1)
                this.showAddBar = false;
            else
                this.showAddBar = true;
			getApp().globalData.schoolId = schoolId;
            var self = this;
            // #ifdef MP-ALIPAY
            my.getSystemInfo({
                  success: function (res) {
                      getApp().globalData.navHeight = res.statusBarHeight + 46;
                      getApp().globalData.windowHeight = res.windowHeight;
                      getApp().globalData.windowWidth = res.windowWidth;
                      self.windowHeight = res.windowHeight;
                  }, fail(err) {
            		console.log(err);
            	}
            })
            // #endif
			this.navH         = getApp().globalData.navHeight;
			this.n            = getApp().globalData.n;
			this.schoolId     = schoolId;
            this.windowHeight = getApp().globalData.windowHeight;
            this.isRegisted   = getApp().globalData.windowHeight;           
		},
		onShow: function() {
			var self = this;
			var schoolId = self.schoolId;
			var has_location = uni.getStorageSync('HAS_LOCATION') || false;
			if (schoolId > 0 || has_location) {
				//不再获取地理位置
				self.initData();
			} else {
				uni.getLocation({
					type: 'wgs84',
					success: function(l) {
						var latitude = l.latitude;
						var longitude = l.longitude;
						getApp().longLat = longitude + ',' + latitude;
						uni.setStorageSync('HAS_LOCATION', getApp().longLat);
						self.initData();
					},
					fail: function() {
						var showLocalButton = uni.getStorageSync('SHOW_LOCAL_BUTTON') || false;
						if (!showLocalButton) {
							uni.setStorageSync('SHOW_LOCAL_BUTTON', 1);
							self.loadText = '无法获取地理位置';
							self.noAddress = true;
							uni.showModal({
								content: '外卖送餐需要您的地理位置',
								confirmText: '去开启',
								success: function(res) {
									if (res.confirm) {
										uni.openSetting({
											success: function(res) {}
										});
									} else {
										self.noAddress = true;
									}
								}
							});
						} else {
							self.initData();
						}
					}
				});
			}
            if(this.backFrom == 'bind_phone'){
                this.loadPacket(2,3);
            }
		},
		methods: {
			beforeInitData() {
				var date = new Date();
				var self = this;
				var time = parseInt(date.getTime() / 1000);
				if (self.shopInfoList.length == 0) {
					self.lockTime = time;
					self.lock = false;
				}
				self.loadData();
			},
			initData() {
				var date = new Date();
				var self = this;
				var time = parseInt(date.getTime() / 1000);
				if (time - self.lockTime > 500) {
					self.loadData();
					self.lockTime = time;
				}
			},
			loadData() {
				var self = this;
				if (self.lock) return false;
				self.lock = true;
				self.loginReg().then(function() {
					//定位
                    self.noNetwork = uni.getStorageSync('noNetwork');
                    if(self.noNetwork){
                        self.noAddress = false;
                    }
					var params = {
						long_lat: getApp().longLat,
						school_id: self.schoolId
					};
					$api_base.post($api_base.homeIndex,params).then(function(res) {
						var data = res.data;
						if (data.ok == 2) {         //新用户
							getApp().globalData.schoolInfo = data.schoolInfo;
							getApp().globalData.userInfo = data.userInfo;
							getApp().globalData.schoolList = data.schoolList;
							getApp().kfPhone = data.kfPhone;
							getApp().isLogin = true;
							self.localSchool = data.schoolInfo.name;
							self.schoolId = data.schoolInfo.id;
							self.categoryList = data.menuList;
							self.imgUrls = data.adList;
							self.localSuccess = true;
							self.pn = 1;
							if (data.userInfo.wxapp_login <= 0) {
								self.showWxappLogin = true;
							}
							self.listEvent(data.schoolList);
							self.loadStore();
							uni.setStorageSync('uid', data.userInfo.uid);
                            
                            self.firstShow = uni.getStorageSync('FIRSTSHOW') || 0; 
                            if(!getApp().globalData.isRegisted && self.firstShow == 0){
                                self.selectCity();
                                uni.setStorageSync('FIRSTSHOW',1);
                            }else{
                                self.loadPacket(2);
                            }
                            if(data.userInfo.bind_phone == 0){
                                self.isRegisted = false; 
                                getApp().globalData.isRegisted = false;
                            }else{
                                self.isRegisted = true;
                                getApp().globalData.isRegisted = true;
                            }
                            
						} else if (data.ok == 1) {
							getApp().globalData.schoolInfo = data.schoolInfo;
							getApp().globalData.userInfo = data.userInfo;
							getApp().globalData.schoolList = data.schoolList;
							getApp().kfPhone = data.kfPhone;
							getApp().isLogin = true; 
                            if(data.userInfo.bind_phone == 0){
                                self.isRegisted = false; 
                                getApp().globalData.isRegisted = false;
                            }else{
                                self.isRegisted = true;
                                getApp().globalData.isRegisted = true;
                            }

							self.localSchool = data.schoolInfo.name;
							self.schoolId = data.schoolInfo.id;
							self.categoryList = data.menuList;
							self.imgUrls = data.adList;
							self.localSuccess = true;
							if (data.userInfo.wxapp_login <= 0) {
								//self.setData({showWxappLogin: true});
							}
							self.listEvent(data.schoolList);
							self.activeTimeEvent(10000);
							self.loadStore();
							uni.setStorageSync('uid', data.userInfo.uid);
                            self.showWxappLogin = true;
                            setTimeout(function(){
                                self.loadPacket(1);
                            },500) 
						}
					});
					self.lock = false;
				});
			},
            loadPacket: function(n,t){
                var self = this;
                self.firstShow = 1;
                var u_id = uni.getStorageSync('openid');
                var r_type = n;
                var school_id = this.schoolId;
                
                $api_base.post($api_base.getRedpackeNew,{u_id:u_id,r_type:r_type,school_id:school_id},1).then(function(res) {
                	var data = res.data;
                    if(data.ok==1){ 
                        if(r_type == 1){   //天降红包
                            if(data.data.length>0){
                                self.packetList = data.data;
                                self.packetShow = true;
                            }

                        }else{
                            if(data.data.whether_have>0){
                                self.newPacket = data.data;
                                if(getApp().globalData.userInfo.bind_phone == 0){    //未绑定手机号
                                    var showNew = uni.getStorageSync('HIDENEWPACKET') || true;
                                    self.newPacketShow = showNew;
                                    if(!self.newPacketShow) self.showPacketBar = true;
                                }else{
                                    getApp().globalData.isRegisted = true;
                                    self.newRedShow  = true;
                                    self.isRegisted  = true;
                                }
                                if(t==3){
                                    getApp().globalData.isRegisted = true;
                                }
                            }
                        }  
                    }else{
                        if(r_type == 2 && t == 3){ 
                            getApp().globalData.isRegisted = true;
                            uni.showToast({
                                title:'该用户已领取过新用户红包！',
                                icon: "none"
                            })
                        }
                    }
                })
            },
			activeTimeEvent: function(s) {
// 				var self = this;
// 				if (s <= 0) {
// 					this.activeTime = ['00', '00', '00'];
// 					clearTimeout(self.activeTimer);
// 					this.groupReload();
// 					return false;
// 				}
// 				var h = new Big(s / 3600).round(0, 0).toString();
// 				// var m = new Big(s % 3600 / 60).round().toString();
// 				var m = parseInt(s % 3600 / 60);
// 				var t = new Big(s % 60).round(0).toString();
// 
// 				if (parseInt(h) < 10) h = '0' + h;
// 				if (parseInt(m) < 10) m = '0' + m;
// 				if (parseInt(t) < 10) t = '0' + t;
// 
// 				this.activeTime = [h, m, t];
// 				this.activeTimer = setTimeout(function() {
// 					self.activeTimeEvent(--s);
// 				}, 1000);
			},
			srollToLeft: function(e) {
				let deltaX = e.detail.deltaX;
				if (deltaX < 0) { //左滑
					this.notShow = false;
				} else {
					this.notShow = true;
				}
			},
			selectCity: function() {
                var self = this;
                if(self.schoolId == 29){
                    self.cascadeVal = [1,0,0];   // 集美大学  学校列表没有回传省市id
                    self.prov_index = 1;
                }else{
                    const index = self.school_list.findIndex(item => item === self.schoolId);
                    self.school_index = index;
                    self.cascadeVal=[0,0,self.school_index];
                }
                console.log(self.cascadeVal);
				var animation = uni.createAnimation({
					duration: 300,
					timingFunction: 'ease'
				});
				this.animation = animation;
				animation.height(1332 + 'rpx').step();
				this.animationData = animation.export();
                this.listEvent(getApp().globalData.schoolList)
			},
			listEvent: function(allData) {
				var self = this;
				var prov = [];
				var city = [];
				var school = [];
				var school_list = [];
				var city_index = self.city_index;
				var prov_index = self.prov_index;
				var school_index = self.school_index;
				var str_func = function(e) {
					if (e.substr(-1, 1) == '市') {
						e = e.substr(0, e.length - 1);
					}
					return e;
				}
				for (let i = 0; i < allData.length; i++) {
					prov.push(allData[i].name)
				}
				if (allData[prov_index].regions) {
					if (allData[prov_index].regions[city_index]) {
						for (let i = 0; i < allData[prov_index].regions.length; i++) {
							city.push(str_func(allData[prov_index].regions[i].name));
						}
						if (allData[prov_index].regions[city_index].regions) {
							for (let i = 0; i < allData[prov_index].regions[city_index].regions.length; i++) {
								school.push(str_func(allData[prov_index].regions[city_index].regions[i].name));
								school_list.push(allData[prov_index].regions[city_index].regions[i].id);
							}
						}
					}
				} else {
					city.push(str_func(allData[prov_index].name));
				}
				self.prov = prov;
				self.city = city;
				self.school = school;
				self.school_list = school_list;
				if (prov.length == 0 || city.length == 0) {
					self.listEvent(getApp().globalData.schoolList);
				}
                this.selectRegion = {
                	prov: prov[this.prov_index],
                	city: city[this.city_index],
                	school: school[this.school_index],
                };
				self.selectSchoolId = school_list[self.school_index];    
			},
			loadStore: function(isAppend = false) {
				var schoolId = this.schoolId;
				var pn = this.pn;
				var sort = this.sort;
				var where = new Object();
				var self = this;
				this.notShow = true;
				this.noMore = false;
				this.selectSort = false;
				where.pn = pn;
				where.school_id = schoolId;
				where.menu_id = this.sort == 5 ? 10 : 0;
				where.sort = sort;
				getApp().globalData.schoolId = schoolId;
				$api_base.post($api_base.storeList,where).then(function(res) {
					let data = res.data;
					if (data.ok == 1) {
                        if(data.hotList && data.hotList.length > 0)
                            self.searchKey = data.hotList[0];
                        else
                            self.searchKey = '搜一搜'
						let source1 = {
							arrowOpen: true
						};
						data.list.forEach(function(v) {
							let arrAll = [];
							Object.assign(v, source1);
							v.active_list.forEach(function(t) {
								let arr = [];
								arr = t.text.split(';');
								let source2 = {
									text: arr
								};
								Object.assign(t, source2);
								arr.forEach((item) => {
									arrAll.push(item);
								});
							})
							let source3 = {
								arrAll: arrAll
							};
							Object.assign(v, source3);
						})
						var isEmpty = data.list.length > 0 ? false : true;
						self.isEmpty = isEmpty;
						if (isAppend) {
							self.shopInfoList = [...self.shopInfoList, ...data.list];
						} else {
							self.shopInfoList = data.list;
                            
						}
						if (data.adList.length < 2) {
							self.indicatorDots = false;
						} else {
							self.indicatorDots = true;
						} 
						self.groupData     = data.groupList || [];
						self.imgUrls       = data.adList || [];
                        self.goodsList     = data.goodsList || [];
						self.recommendInfo = data.recommendInfo || null;
						self.oneselfList   = data.oneselfList || [];
						self.oneselfCount  = data.oneselfCount || 0;
                        self.current       = 2;
                        self.countList     = data.count_list;
                        getApp().globalData.countList = self.countList;
                        self.$nextTick(function() {
                            self.current   = 0;
                        });
                        if(self.shopInfoList.length==0) self.noMore = true;
						
					}
				});
			},
			sortEvent: function(n) {
                var self = this;
                let showAddBar = self.showAddBar;     
                const query1 = uni.createSelectorQuery();
                query1.select('.scroll-height').boundingClientRect();
                query1.selectViewport().scrollOffset();
                query1.exec(function(res){ 
                    console.log(self.navH);
                    // #ifdef MP-WEIXIN   
                        if(showAddBar)
                            self.scrollTop = res[0].height-self.navH - 40;
                        else
                            self.scrollTop = res[0].height-self.navH - 10;
                    // #endif
                    // #ifdef MP-ALIPAY
                        self.scrollTop = res[0].height-self.navH - 10;
                    // #endif
                    uni.pageScrollTo({
                        scrollTop:self.scrollTop,
                        duration: 0
                    }); 
                })
                // #ifdef MP-WEIXIN                    
                    let top = showAddBar ? 147 : 117; 
                // #endif
                // #ifdef MP-ALIPAY
                    let top = 36; 
                // #endif
                self.loadBeforeHeight = self.windowHeight - top - 10;
                this.pn = 1
				if (n == 0) {
					if (this.sort > 2) {
						this.sort = this.pickerSelect;  
					} else {
						this.selectSort = !this.selectSort;
						return;
					}
                    this.loadStore(false);
				} else if (n <= 2) {
					this.selectSort = !this.selectSort;
					this.sort = n;
					this.pickerSelect = n;
                    this.loadStore(false);
				} else {
					this.sort = n;
				}
                if(this.sort == 3){
                    this.loadOneselfList();
                }
                if(this.sort == 4){
                    this.loadGroupList();
                }
                if(this.sort == 5){
                    this.loadStore();
                }   
               
			},
            loadGroupList: function (isAppend) {
                var schoolId = this.schoolId;
                var self  = this;
                this.navH = getApp().globalData.navHeight;
                this.n    = getApp().globalData.n;
                this.leftNav  = getApp().globalData.windowWidth/2;
                $api_base.post($api_base.getGroupList,{school_id: schoolId}).then(function(e){
                    let data = e.data;
                    if (data.ok == 1) {
                        self.isEmpty      = data.groupList.length > 0 ? false : true;
                        self.shopInfoList = data.groupList;
                    }
                });
            },
            loadOneselfList: function (isAppend) {
                var pn = this.pn;
                var where = new Object();
                var self = this;
                where.pn = pn;
                where.school_id = this.schoolId;
                $api_base.post($api_base.getOneselfList,where).then(function(res) {
                    let data = res.data;
                    if (data.ok == 1) {
                        var isEmpty = data.list.length > 0 ? false : true;
                        self.isEmpty = isEmpty;
                        if (!isEmpty){
                          let source1 = { arrowOpen: true };
                          data.list.forEach(function (v) {
                            let arrAll = [];
                            Object.assign(v, source1);
                            v.active_list.forEach(function (t) {
                              let arr = [];
                              arr = t.text.split(';');
                              let source2 = { text: arr };
                              Object.assign(t, source2);
                              arr.forEach((item) => {
                                arrAll.push(item);
                              });
                            })
                            let source3 = { arrAll : arrAll};
                            Object.assign(v, source3);
                          })
                          
                        }
                        if (isAppend) {
                            self.shopInfoList = [...self.shopInfoList, ...data.list];
                        } else {
                            self.shopInfoList = data.list;
                        }
                    }
                });
            },
			openSelect: function() {
				this.selectSort = !this.selectSort;
			},
			toSearch: function(n) {
				let v = n || '';
				uni.navigateTo({
					url: '/pagesOther/search/index?val=' + v
				})
			},
            onShareAppMessage: function () {
                var self = this;
                return {
                    title: '同学快跑',
                    path: 'pages/index/index?schoolId=' + self.schoolId,
                    imageUrl: 'http://img1.birdback.org/a/c5/6c/c56c56f95bc2d919a3807fde2d5adb8e.png',
                    success: function (res) {
                       
                    },
                    fail: function (res) {
                        // 转发失败
                    }
                } 
            },
			bindChange: function(e) { 
				const val = e.detail.value;
				this.prov_index   = val[0];
				this.city_index   = val[1];
				this.school_index = val[2];
				this.listEvent(getApp().globalData.schoolList);
			},
			enterEvent: function() {
                var self = this;
                self.localSchool = "定位中..."
				var animation = uni.createAnimation({
					duration: 500,
					timingFunction: 'ease',
				});
                animation.height(0 + 'rpx').step()
                self.animationData = animation.export();
				var date           = new Date();
				var time           = parseInt(date.getTime() / 1000);
				this.lockTime      = time;
				this.lock          = false;
				this.pn            = 1;
                this.sort          = 1;
                setTimeout(function() {
                    var selectData    = self.selectRegion;
                    self.animation    = animation;
                    self.shopInfoList = [];
                    self.localSchool  = self.selectRegion.school;
                    self.schoolId = self.selectSchoolId;
                    getApp().globalData.schoolInfo = {
                    	id: self.selectSchoolId,
                    	name: selectData.school
                    };
                    self.loadStore();
                }, 500);
                if(self.firstShow == 0){     //首次进入
                    setTimeout(function(){
                        self.loadPacket(2);
                    },500)
                } 
			},
			cancelEvent: function() {
				var animation = uni.createAnimation({
					duration: 500,
					timingFunction: 'ease'
				})
				this.animation = animation
				animation.height(0 + 'rpx').step()
				this.animationData = animation.export();
				this.isCk          = false;
				this.selectRegion  = {};
                this.cascadeVal = [0,0,0];
			},
            goOneself: function () {
                uni.navigateTo({
                    url: '/pages/index/oneself/index?schoolId=' + this.schoolId,
                })
            },
            activeEvent: function(){
                uni.navigateTo({
                    url: '/pagesOther/goods-active/index?schoolId=' + this.schoolId,
                })
            },
            groupEvent: function(){
                uni.navigateTo({
                    url: '/pagesOther/group-active/index?schoolId=' + this.schoolId,
                })
            },
            menuEvent: function (e) {
                var idx = e.currentTarget.dataset.id;
                var index = e.currentTarget.dataset.index;
                var data = this.categoryList[0][index];
                this.link(data);
            },
            adEvent: function (e) {
                var index = e.currentTarget.dataset.index;
                var data = this.imgUrls[index];
                this.link(data);
            },
            link: function (data) {
                if (data.type == 1) {
                  uni.navigateTo({ url: data.relate_info.pages + '&sid=ad&adId=' + data.id });
                } else if (data.type == 2) {
                  wx.navigateToMiniProgram({
                    appId: data.relate_info.app_id,
                    path: data.relate_info.pages,
                    envVersion: 'develop',
                    success(res) {
                    }
                  });
                } else if (data.type == 3) {
                    uni.navigateTo({ url: '/pages/webview/index?url=' + data.relate_info.pages });
                } else if (data.type == 4) {
                   // app.WxService.alert(data.relate_info.msg);
                } else if(data.type == 6) {
                    uni.navigateTo({ url: '/pagesOther/imageview/index?url=' + data.relate_info.pages });
                }
            },
            goOneselfStore: function (e) {
                var storeId = e.currentTarget.dataset.storeid;
                uni.navigateTo({
                  url: '/pages/goods/goods?storeId=' + storeId + '&sid=oneself',
                })
            },
            openGroupStore: function (e) {
                var storeId = e.currentTarget.dataset.id;
                var finishTime = e.currentTarget.dataset.time;
                uni.navigateTo({
                    url: '/pages/goods/goods?storeId=' + storeId + '&finishTime=' + finishTime +'&sid=group',
                })
            },
            openDiscount: function (e) {
                var storeId = e.currentTarget.dataset.storeid;
                this.shopInfoList.find(item => {
                  if (item.id == storeId)
                    item.arrowOpen = !item.arrowOpen;
                })
                const that = this;
                that.shopInfoList = [...that.shopInfoList];
            },
            openStore: function (e) {
                var storeId = e.currentTarget.dataset.storeid;
                // #ifdef MP-WEIXIN
                var categoryId = e.currentTarget.dataset.categoryid || '';
                // #endif
				// #ifdef MP-ALIPAY
				var categoryId = e.currentTarget.dataset.categoryId || '';
				// #endif
                var id = e.currentTarget.dataset.id || '';
                getApp().globalData.scene = null;
                if(this.sort == 3){
                    uni.navigateTo({
                      url: '/pages/goods/goods?storeId=' + storeId + '&sid=oneself' + '&categoryId=' + categoryId + '&id=' + id ,
                    })
                }else{
                    uni.navigateTo({
                      url: '/pages/goods/goods?storeId=' + storeId + '&sid=index' + '&categoryId=' + categoryId + '&id=' + id ,
                    })
                }
            },
            addToMine: function(){
                this.addMine = false;
                var isMine = 1;
                uni.setStorageSync('ISMINE',isMine);
            },
            closeBox: function(){
                this.newPacketShow = false;
                this.showLoginoutTip = false;
                this.showPacketBar = true;
                uni.setStorageSync('HIDENEWPACKET',this.newPacketShow);
            },
            closePacketBar: function(){
                this.showPacketBar = false;
            },
            getPacket: function(){
                this.showLoginoutTip = false;
            },
            hidePacketBox: function(){
                this.packetShow = false;
            },
            hideNewPacketBox: function(){
               // this.newPacketShow = false;
                this.showLoginoutTip = true;
                
            },
            showAdd: function(){
                this.showAddBar = false;
                this.addMine = true;
            },
            getPhoneNumber: function(e){
                var self = this;
                if (e.detail.errMsg == 'getPhoneNumber:ok') {
                    $api_base.post($api_base.getDecryptData,{encryptedData: e.detail.encryptedData, iv: e.detail.iv,school_id: self.schoolId}).then(function (e) {
                        let data = e.data;
                        self.newPacketShow = false;
                        self.showPacketBar = false;
                        if(data.ok == 0){
                            self.newRedShow = false;
                            uni.showModal({
                             	title: '',
                             	content: '领取失败.',
                             	showCancel: false,
                             	confirmText: '知道了',
                             	confirmColor: '#00B89D',
                             	success(res) {
                             		if (res.confirm) {
                             			console.log('用户点击确定')
                             		} else if (res.cancel) {
                             			console.log('用户点击取消')
                             		}
                             	}
                            })
                        }else if(data.ok == 1){ 
                            getApp().globalData.userInfo.bind_phone = 1;
                            getApp().globalData.isRegisted = true;
                            self.isRegisted    = true;
                            self.loadPacket(2,3);
                        }
                    })
                }else{
                    uni.navigateTo({
                        url:'/pages/index/bind-phone/index?from=index'
                    })
                    //self.showLoginoutTip = true;
                }
            },
            hideNewRed: function(){
                this.newRedShow = false;
            },
            onGetAuthorize: function(res){
                var self = this;
                my.getPhoneNumber({
                    success: (res) => {
                        let encryptedData = res.response;
                        $api_base.post($api_base.getAliDecryptData,res).then(function (e) {
                            let data = e.data;
                            self.newPacketShow = false;
                            self.showPacketBar = false;
                            if(data.ok == 0){
                                self.newRedShow = false;
                                uni.showModal({
                                 	title: '',
                                 	content: '领取失败.',
                                 	showCancel: false,
                                 	confirmText: '知道了',
                                 	confirmColor: '#00B89D',
                                 	success(res) {
                                 		if (res.confirm) {
                                 			console.log('用户点击确定')
                                 		} else if (res.cancel) {
                                 			console.log('用户点击取消')
                                 		}
                                 	}
                                })
                            }else if(data.ok == 1){ 
                                // self.newRedShow    = true;
                                self.loadPacket(2,3);
                                getApp().globalData.userInfo.bind_phone = 1;
                                getApp().globalData.isRegisted = true;
                                self.isRegisted    = true;
                            }
                        })
                    },
                    fail: (res) => {
                        console.log(res);
                        console.log('getPhoneNumber_fail');
                    },
                });
            },
            onAuthError(e) {  
                console.error(e);  
                uni.navigateTo({
                    url:'/pages/index/bind-phone/index?from=index'
                })
            }  
		},
        onReachBottom: function () {
            var pn = this.pn;
            var pc = this.pc;
            var count = this.shopInfoList.length;
            if (pn * pc <= count) {
                this.pn++;
                if(this.sort<3)
                    this.loadStore(true);
                else if(this.sort == 3)
                    this.loadOneselfList(true)
                else if(this.sort == 4)
                    this.loadGroupList(true)
                else if(this.sort == 5)
                    this.loadStore(true)
            } else {
              this.noMore = true;
            }
        },

		onPageScroll(ret){
			let self = this;
            let showAddBar = self.showAddBar;
			const query1 = uni.createSelectorQuery();
			query1.select('.menu_tab_under').boundingClientRect();
			query1.selectViewport().scrollOffset();
			query1.exec(function(res){ 
				let top = res[0].top;
                let n = 0;  
                    // #ifdef MP-WEIXIN
                    n = showAddBar ? 147 : 117;
                    if(top<n){ 
                    	self.menuFixed = true;
                    	self.menuTop   = showAddBar ? self.navH + 70 : self.navH + 40;
                    }else{
                        
                    	self.menuFixed = false;
                    	self.menuTop   = 0;
                        
                    }   
                    // #endif
                    // #ifdef MP-ALIPAY
                    n = 38;
                    if(top<n){
                    	self.menuFixed = true;
                    	self.menuTop   = 40;
                    }else{
                    	self.menuFixed = false;
                    	self.menuTop   = 0;
                    }   
                    // #endif
                
			});
            const query2 = uni.createSelectorQuery();
			query2.select('.address_head').boundingClientRect();
			query2.selectViewport().scrollOffset();
			query2.exec(function(res){ 
				let top = res[0].top;
                let m = 0;
                // #ifdef MP-WEIXIN
                    m = showAddBar ? 65 : 35;
                    if(top<m){
                        self.searchFixed = true;
                        self.searchTop = showAddBar ? self.navH + 31 : self.navH;
                    }else{
                        self.searchFixed = false;
                        self.searchTop = 0;
                    }
                // #endif
                // #ifdef MP-ALIPAY
                m = -30;
                if(top<m){
                    self.searchFixed = true;
                    self.searchTop = 0;
                }else{
                    self.searchFixed = false;
                    self.searchTop = 0;
                }
                // #endif
			});
		}
       
	};
</script>
<style>
  page {
  background-color: #fff;
  }
</style>
<style lang="scss" scoped>
	@import 'index.scss';
</style>
